package com.xander.myblog.controller;

import com.xander.myblog.entity.Article;
import com.xander.myblog.entity.Topic;
import com.xander.myblog.entity.User;
import com.xander.myblog.service.ArticleService;
import com.xander.myblog.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 叶振东
 * @date 2018-12-20
 */
@Controller
@RequestMapping("system")
public class SystemController {
    @Autowired
    private TopicService topicService;
    @Autowired
    private ArticleService articleService;

    @RequestMapping("publish")
    public String publish(Long articleId, HttpSession session,HttpServletRequest request){
        if(session.getAttribute("user")==null||((User)session.getAttribute("user")).getPermission()!=1){
            return "unauth";
        }else{
            if(articleId!=null){
                Article article=articleService.getArticleByAid(articleId);
                request.setAttribute("article",article);
            }
            List<Topic> topics=topicService.getExistTopic();
            request.setAttribute("topics",topics);
            return "system/publish";
        }
    }

    @RequestMapping("topic")
    public String topic(){
        return "system/topic";
    }
}
